home *** CD-ROM | disk | FTP | other *** search
- /*
- * Test program to demonstrate case insensitivity of NBP
- * two names are registered and confirmed. A lookup is performed with both lower case and
- * upper case inital letters of the object.
- * Use a debugger statement to halt program execution while a network tool is used to
- * examine entities registered to the netwrok.
- * Also useful for demonstrating the use of the PSetSelfSend capability.
- */
-
- /* Use the following instructions to build this programm assuming this file is named 'testnbp.c'
-
- C -r 'testNBP.c'
- Link -d -c '????' -t APPL ∂
- 'testNBP.c.o' ∂
- "{CLibraries}"StdClib.o ∂
- "{MPW}"Libraries:Libraries:SIOW.o ∂
- "{Libraries}"Runtime.o ∂
- "{Libraries}"Interface.o ∂
- -o testnbp
- Rez -a "{MPW}"Interfaces:Rincludes:SIOW.r -o testnbp
-
- */
-
-
- #if !defined(USEDUMP)
- #include <Types.h>
- #include <OSUtils.h>
- #include <Appletalk.h>
- #include <Memory.h>
- #include <Strings.h>
- #include <String.h>
- #include <stdio.h>
- #include <Events.h>
- #include <StdLib.h>
- #if defined(MAKEDUMP)
- #pragma dump "nbpDumpFile"
- #endif
- #else
- #pragma load "nbpDumpFile"
- #endif
-
-
- #include <Types.h>
- #include <OSUtils.h>
- #include <Appletalk.h>
- #include <Memory.h>
- #include <Strings.h>
- #include <String.h>
- #include <stdio.h>
- #include <Events.h>
- #include <StdLib.h>
-
-
- OSErr result;
- ATPParamBlock my_atp;
- MPPParamBlock my_nbp,self;
- NamesTableEntry entity1, entity2, entity3;
- char tempBuffer[2048];
- short input;
- char *nbpObject, *nbpType, *nbpZone;
- char newSocket;
- short tempNode;
- char saveSelfState;
-
- main()
- {
- if (MPPOpen() != noErr) {
- printf("Error opening MPP - Aborting program!\n");
- fflush(stdout);
- exit(-1);
- }
-
- if (ATPLoad() != noErr) {
- printf("Error opening ATP - Aborting program!\n");
- fflush(stdout);
- exit(-1);
- }
-
- /* open a socket */
- my_atp.ATP.atpSocket = 0;
- my_atp.ATP.addrBlock.aNet = 0;
- my_atp.ATP.addrBlock.aNode = 0;
- my_atp.ATP.addrBlock.aSocket = 0;
- result = POpenATPSkt(&my_atp, false);
- printf("Result of opening socket was %d.\n", result);
- printf("atpSocket is %u.\n", (unsigned char) my_atp.ATP.atpSocket);
-
- /* Get the current node address info for PConfirmName */
- GetNodeAddress(&tempNode, (short *) &my_atp.ATP.addrBlock.aNet);
- my_atp.ATP.addrBlock.aNode = tempNode;
- my_atp.ATP.addrBlock.aSocket = my_atp.ATP.atpSocket;
-
- printf("addrBlock.aNet is %d.\n", my_atp.ATP.addrBlock.aNet);
- printf("addrBlock.aNode is %d.\n", my_atp.ATP.addrBlock.aNode);
- printf("addrBlock.aSocket is %d.\n\n", my_atp.ATP.addrBlock.aSocket);
- fflush(stdout);
-
- if (result != noErr) {
-
- printf("Error opening socket - Aborting program!\n");
- fflush(stdout);
- exit(-1);
- }
-
- /* set selfsend so that we can see ourselves */
- printf("Setting Self Send state to true.\n");
- self.SETSELF.newSelfFlag = 1;
- PSetSelfSend(&self, false);
- saveSelfState = self.SETSELF.oldSelfFlag;
-
- if (saveSelfState)
- printf("Old Self send state was true.\n");
- else
- printf("Old Self send state was false.\n\n");
-
-
-
- /* register first item with upper case initial letters */
- nbpObject = "\pa";
- nbpType = "\pComputer Server";
- nbpZone = "\p*";
-
-
- NBPSetNTE ((Ptr) &entity1, (Ptr)nbpObject, (Ptr)nbpType, (Ptr)nbpZone, my_atp.ATP.atpSocket);
- my_nbp.NBP.NBPPtrs.ntQElPtr = (Ptr) &entity1;
- my_nbp.NBP.interval = 4;
- my_nbp.NBP.count = 2;
- my_nbp.NBP.parm.verifyFlag = true;
-
- result = PRegisterName(&my_nbp, false);
-
- printf("Result of first register was %d.\n", result);
- printf("ioResult returned %d.\n", my_nbp.NBP.ioResult);
-
- fflush(stdout);
-
- /* Confirm first name */
- NBPSetEntity ((Ptr) &entity1.nt.entityData[0], (Ptr)nbpObject, (Ptr)nbpType, (Ptr)nbpZone);
- my_nbp.NBP.NBPPtrs.entityPtr = (Ptr) &entity1.nt.entityData[0];
- my_nbp.NBP.interval = 4;
- my_nbp.NBP.count = 3;
- BlockMove ((Ptr) &my_atp.ATP.addrBlock, (Ptr) &my_nbp.NBP.parm.Confirm.confirmAddr, sizeof(AddrBlock));
-
- result = PConfirmName(&my_nbp, false);
-
- printf("Result of first confirm was %d.\n", result);
- printf("ioResult returned %d.\n\n", my_nbp.NBP.ioResult);
- fflush(stdout);
-
- /* Register second name with lower case initial letters */
- nbpObject = "\pb";
- nbpType = "\pcomputer server";
-
- NBPSetNTE ((Ptr) &entity2, (Ptr)nbpObject, (Ptr)nbpType, (Ptr)nbpZone, my_atp.ATP.atpSocket);
- my_nbp.NBP.NBPPtrs.ntQElPtr = (Ptr) &entity2;
- my_nbp.NBP.interval = 8;
- my_nbp.NBP.count = 3;
- my_nbp.NBP.parm.verifyFlag = true;
-
- result = PRegisterName(&my_nbp, false);
-
- printf("Result of second register was %d.\n", result);
- printf("ioResult returned %d.\n", my_nbp.NBP.ioResult);
- fflush(stdout);
-
- /* Confirm second name */
- NBPSetEntity ((Ptr) &entity2.nt.entityData[0], (Ptr)nbpObject, (Ptr)nbpType, (Ptr)nbpZone);
- my_nbp.NBP.NBPPtrs.entityPtr = (Ptr) &entity2.nt.entityData[0];
- my_nbp.NBP.interval = 8;
- my_nbp.NBP.count = 3;
- BlockMove ((Ptr) &my_atp.ATP.addrBlock, (Ptr) &my_nbp.NBP.parm.Confirm.confirmAddr, sizeof(AddrBlock));
-
- result = PConfirmName(&my_nbp, false);
-
- printf("Result of second confirm was %d.\n", result);
- printf("ioResult returned %d.\n\n", my_nbp.NBP.ioResult);
- fflush(stdout);
-
-
- /* lookup with lower case name */
- nbpObject = "\p=";
- /* nbpObject = "\p≈"; */
- nbpType = "\pcomputer server";
-
- NBPSetEntity ((Ptr) &entity3.nt.entityData[0], (Ptr)nbpObject, (Ptr)nbpType, (Ptr)nbpZone);
- my_nbp.NBP.NBPPtrs.entityPtr = (Ptr) &entity3.nt.entityData[0];
- my_nbp.NBP.interval = 4;
- my_nbp.NBP.count = 3;
- my_nbp.NBP.parm.Lookup.retBuffPtr = &tempBuffer;
- my_nbp.NBP.parm.Lookup.retBuffSize = 2048;
- my_nbp.NBP.parm.Lookup.maxToGet = 20;
-
- result = PLookupName(&my_nbp, false);
-
- printf("Result of lower case lookup was %d.\n", result);
- printf("ioResult was %d.\n", my_nbp.NBP.ioResult);
- printf("NumGotten was %d.\n\n", my_nbp.NBP.parm.Lookup.numGotten);
- fflush(stdout);
-
- /* lookup with upper case name */
- nbpType = "\pComputer Server";
-
- NBPSetEntity ((Ptr) &entity3.nt.entityData[0], (Ptr)nbpObject, (Ptr)nbpType, (Ptr)nbpZone);
- my_nbp.NBP.NBPPtrs.entityPtr = (Ptr) &entity3.nt.entityData[0];
- my_nbp.NBP.interval = 4;
- my_nbp.NBP.count = 3;
- my_nbp.NBP.parm.Lookup.retBuffPtr = &tempBuffer;
- my_nbp.NBP.parm.Lookup.retBuffSize = 2048;
- my_nbp.NBP.parm.Lookup.maxToGet = 20;
-
- result = PLookupName(&my_nbp, false);
-
- printf("Result of upper case lookup was %d.\n", result);
- printf("ioResult was %d.\n", my_nbp.NBP.ioResult);
- printf("NumGotten was %d.\n\n", my_nbp.NBP.parm.Lookup.numGotten);
- fflush(stdout);
-
- /* Restore self send state */
- self.SETSELF.newSelfFlag = saveSelfState;
- PSetSelfSend(&self, false);
- saveSelfState = self.SETSELF.oldSelfFlag;
-
-
- /* Remove names */
- my_nbp.NBP.NBPPtrs.entityPtr = (Ptr) &entity1.nt.entityData[0];
- result = PRemoveName(&my_nbp, false);
- printf("Result of removing entity1 was %d.\n", result);
-
- my_nbp.NBP.NBPPtrs.entityPtr = (Ptr) &entity2.nt.entityData[0];
-
- result = PRemoveName(&my_nbp, false);
- printf("Result of removing entity2 was %d.\n", result);
-
- result = PCloseATPSkt(&my_atp, false);
- printf("Result of closing socket was %d.\n", result);
- fflush(stdout);
- ATPUnload();
- }
-